﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="EditCaseFrm.aspx.cs" Inherits="WebApp.EditCaseFrm" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>箱号资料</title>
    <link rel="stylesheet" type="text/css" href="css/newStyle.css" />
    <link rel="stylesheet" type="text/css" href="js/jquery-easyui-1.3.2/themes/default/easyui.css" />
    <link rel="stylesheet" type="text/css" href="js/jquery-easyui-1.3.2/themes/icon.css" />

    <script type="text/javascript" src="js/common.js"></script>

    <script type="text/javascript" src="js/jquery-easyui-1.3.2/jquery-1.8.0.min.js"></script>

    <script type="text/javascript" src="js/jquery-easyui-1.3.2/jquery.easyui.min.js"></script>

    <script type="text/javascript" src="js/Jquery.Query.js"></script>

    <script type="text/javascript" src="js/jquery-easyui-1.3.2/locale/easyui-lang-zh_CN.js"></script>

    <script type="text/javascript">
        $(document).ready(function() {
            initParams();
        });

        function initParams() {
            var orderId = $.query.get('OrderId');
            var caseId = $.query.get('CaseId');
            $('#orderId').val(orderId);
            $('#editId').val(caseId);
            initData();
            bindCase();
        }

        function bindCase() {
            var id = $('#editId').val();
            if (id) {
                WebApp.EditCaseFrm.GetCase(id, function callback(p) {
                    if (p.error) {
                        $.messager.alert('异常消息', '获取数据异常,' + p.error.Message, 'error');
                        return;
                    }

                    var res = p.value;
                    if (res) {
                        var data = res.Data;
                        var msg = res.Msg;
                        if (msg)
                            $.messager.alert('箱号信息获取异常', msg, 'error');
                        else {
                            if (data) {
                                $('#eCaseCode').val(data.code);
                                $('#eCaseModel').val(data.model);
                                $('#eCaseTitle').val(data.title);
                                $('#eCaseCarNo').val(data.carNo);
                                $('#eCaseCheck').val(data.check);
                                $('#eCaseTrailer').val(data.trailer);
                                $('#eCaseTel').val(data.tel);
                                $('#eCaseDriver').val(data.driver);
                                $('#eCaseMemo').val(data.memo);
                            }
                        }
                    }
                });
            }
        }

        function initData() {

        }

        function resetFrm() {
            $('#fm').form('clear');
        }

        function addCase() {
            resetFrm();
        }

        function saveCase() {
            var validate = $('#fm').form('validate');
            if (!validate)
                return;
            var id = $('#editId').val();
            var orderId = $('#orderId').val();
            var eCaseCode = $('#eCaseCode').val();
            var eCaseModel = $('#eCaseModel').val();
            var eCaseTitle = $('#eCaseTitle').val();
            var eCaseCarNo = $('#eCaseCarNo').val();
            var eCaseCheck = $('#eCaseCheck').val();
            var eCaseTrailer = $('#eCaseTrailer').val();
            var eCaseTel = $('#eCaseTel').val();
            var eCaseDriver = $('#eCaseDriver').val();
            var eCaseMemo = $('#eCaseMemo').val();

            WebApp.EditCaseFrm.SaveCase(id, orderId, eCaseCarNo, eCaseCheck, eCaseCode, eCaseDriver, eCaseMemo, eCaseModel, eCaseTel, eCaseTitle, eCaseTrailer, function callback(p) {
                if (p.error) {
                    $.messager.alert('异常消息', '提交保存异常,' + p.error.Message, 'error');
                    return;
                }

                var res = p.value;
                if (res) {
                    var data = res.Data;
                    var msg = res.Msg;
                    if (msg)
                        $.messager.alert('箱号信息获取异常', msg, 'error');
                    else {
                        refreshParent(orderId);
                        if (id) {
                            if (data > 0) {
                                $.messager.alert('消息', '箱号信息已更新!', 'info');
                                $('#editId').val(data);
                            }
                            else
                                $.messager.alert('箱号信息更新异常', msg, 'error');
                        }
                        else {
                            if (data > 0) {
                                $.messager.alert('消息', '箱号信息已创建!', 'info');
                                $('#editId').val(data);
                            }
                            else
                                $.messager.alert('箱号信息创建异常', msg, 'error');
                        }
                    }
                }
            });
        }

        function deleteCase() {
            var id = $('#editId').val();
            var orderId = $('#orderId').val();
            WebApp.EditCaseFrm.DeleteCase(id, orderId, function callback(p) {

                if (p.error) {
                    $.messager.alert('异常消息', '提交删除异常,' + p.error.Message, 'error');
                    return;
                }
                var res = p.value;
                if (res) {
                    var data = res.Data;
                    var msg = res.Msg;
                    if (msg)
                        $.messager.alert('删除异常', msg, 'error');
                    else {
                        if (data == true) {
                            $.messager.alert('消息', '箱号信息已删除!', 'info');
                            refreshParent(orderId);
                        }
                        else
                            $.messager.alert('删除箱号失败', msg, 'error');
                    }
                }
            });
        }

        function refreshParent(orderId) {
            window.parent.bindCase(orderId);
        }
    </script>

</head>
<body>
    <form id="Form1" method="post" runat="server">
    </form>
    <div>
        <form id="fm">
        <div style="padding: 5px; border: 1px solid #ddd">
            <a href="#" id="btnAdd" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-add'"
                onclick="addCase()">新增</a> <a href="#" id="btnSave" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-save'"
                    onclick="saveCase()">保存</a> <a href="#" id="btnDelete" class="easyui-linkbutton"
                        data-options="plain:true,iconCls:'icon-remove'" onclick="deleteCase()">删除</a>
        </div>
        <div class="easyui-panel" title="箱号资料" style="width: 500px; padding: 5px;">
            <table>
                <tr>
                    <td style="text-align: left">
                        箱号：
                    </td>
                    <td style="text-align: left">
                        <input type="text" id="eCaseCode" style="width: 150px" class="easyui-validatebox" />
                    </td>
                    <td style="text-align: left">
                        箱型：
                    </td>
                    <td style="text-align: left">
                        <input type="text" id="eCaseModel" style="width: 150px" class="easyui-validatebox" />
                    </td>
                </tr>
                <tr>
                    <td style="text-align: left">
                        封号：
                    </td>
                    <td style="text-align: left">
                        <input type="text" id="eCaseTitle" style="width: 150px" />
                    </td>
                    <td style="text-align: left">
                        车牌号：
                    </td>
                    <td style="text-align: left">
                        <input type="text" id="eCaseCarNo" style="width: 150px" />
                    </td>
                </tr>
                <tr>
                    <td style="text-align: left">
                        查验封：
                    </td>
                    <td style="text-align: left">
                        <input type="text" id="eCaseCheck" style="width: 150px" />
                    </td>
                    <td style="text-align: left">
                        拖车：
                    </td>
                    <td style="text-align: left">
                        <input type="text" id="eCaseTrailer" style="width: 150px" />
                    </td>
                </tr>
                <tr>
                    <td style="text-align: left">
                        电话：
                    </td>
                    <td style="text-align: left">
                        <input type="text" id="eCaseTel" style="width: 150px" />
                    </td>
                    <td style="text-align: left">
                        司机：
                    </td>
                    <td style="text-align: left">
                        <input type="text" id="eCaseDriver" style="width: 150px" />
                    </td>
                </tr>
                <tr>
                    <td style="text-align: left">
                        备注：
                    </td>
                    <td style="text-align: left" colspan="3">
                        <input type="text" id="eCaseMemo" style="width: 250px" />
                    </td>
                </tr>
            </table>
        </div>
        <input id="editId" type="hidden" />
        </form>
        <input id="orderId" type="hidden" />
    </div>
</body>
</html>
